package com.kws.system.api;

import com.kws.system.api.domain.QueryAccessTokenInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import com.kws.common.core.constant.SecurityConstants;
import com.kws.common.core.constant.ServiceNameConstants;
import com.kws.common.core.domain.R;
import com.kws.system.api.domain.SysUser;
import com.kws.system.api.factory.RemoteUserFallbackFactory;
import com.kws.system.api.model.LoginUser;

/**
 * 用户服务
 * 
 * @author zhangyh
 */
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService
{
    /**
     * 通过用户名查询用户信息
     *
     * @param username 用户名
     * @param source 请求来源
     * @return 结果
     */
    @GetMapping("/user/info/{username}")
    public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 注册用户信息
     *
     * @param sysUser 用户信息
     * @param source 请求来源
     * @return 结果
     */
    @PostMapping("/user/register")
    public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 记录用户登录IP地址和登录时间
     *
     * @param sysUser 用户信息
     * @param source 请求来源
     * @return 结果
     */
    @PutMapping("/user/recordlogin")
    public R<Boolean> recordUserLogin(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/user/query/openId")
    R<LoginUser> checkUserByAppCode(@RequestBody QueryAccessTokenInfo info, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/user/getUser/{userId}")
    R<SysUser> getUserById(@PathVariable(value = "userId", required = false) Long userId);


    @GetMapping("/user/getUserByPhone/{phone}")
    R<LoginUser> checkUserByUserPhone(@PathVariable("phone") String phone, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/user/register/user/byPhone")
    R registerUserUser(@RequestParam(value = "phone") String phone,
                       @RequestParam(value = "userType") String userType,
                       @RequestParam(value = "password") String password,
                       @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @GetMapping("/user/bind/userPhone/byOpenId")
    R<LoginUser> bindUserOpenId(@RequestParam(value = "openId") String openId,
                                @RequestParam(value = "phone")  String phone,
                                @RequestParam(value = "channel") String channel,
                                @RequestHeader(SecurityConstants.FROM_SOURCE) String inner);

//    @GetMapping("/get/smallProgram/userInfo")
//    R<LoginUser> getSmallProgram(@RequestParam(value = "openId") String openId,
//                                 @RequestParam(value = "userPhoneNumber") String userPhoneNumber,
//                                 @RequestHeader(SecurityConstants.FROM_SOURCE) String inner);
}
